#!/usr/bin/python3.8
# -*- coding: utf-8 -*-
# @Time    : 2021/3/13 11:37 上午
# @Author  : zhaohexin
# @Email   : 1483643520@xxx.com
# @File    : Redis.py
# @Software: PyCharm
# @FileDescription：Redis通用方法

import sys
import redis

from core.config import settings


class RedisCli:
    """
    redis 连接
    """

    def __init__(self, mold):
        # 获取那种数据库连接
        self.redis_config = settings.REDIS.get(mold)
        self.redis_connect = redis.Redis(**self.redis_config)

    # 使实例化后的对象 赋予redis对象的的方法和属性
    def __getattr__(self, name):
        return getattr(self.redis_connect, name)

    def __getitem__(self, name):
        return self.redis_connect[name]

    def __setitem__(self, name, value):
        self.redis_connect[name] = value

    def __delitem__(self, name):
        del self.redis_connect[name]
